home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / hp48_1 / dig.log < prev    next >
Internet Message Format  |  1995-03-23  |  11KB

  1. From gcw20877@uxa.cso.uiuc.edu  Mon Oct 15 00:03:36 1990
  2. Received: from bank.ecn.purdue.edu by en.ecn.purdue.edu (5.61/1.27jrs)
  3.     id AA10583; Mon, 15 Oct 90 00:03:36 -0500
  4. Received: from uxa.cso.uiuc.edu by bank.ecn.purdue.edu (5.61/1.27jrs)
  5.     id AA29377; Mon, 15 Oct 90 00:03:22 -0500
  6. Received: by uxa.cso.uiuc.edu id AA07804
  7.   (5.65+/IDA-1.3.5 for wscott@ecn.purdue.edu); Mon, 15 Oct 90 00:02:36 -0500
  8. Date: Mon, 15 Oct 90 00:02:36 -0500
  9. From: George Wang <gcw20877@uxa.cso.uiuc.edu>
  10. Message-Id: <9010150502.AA07804@uxa.cso.uiuc.edu>
  11. To: wscott@ecn.purdue.edu
  12. Status: OR
  13.  
  14. Article 3332 of comp.sys.handhelds:
  15. Path: ux1.cso.uiuc.edu!iuvax!cica!sol.ctr.columbia.edu!samsung!cs.utexas.edu!uunet!mcsun!ukc!axion!tharr!siva.bristol.ac.uk
  16. From: ard@siva.bristol.ac.uk (Tony Duell)
  17. Newsgroups: comp.sys.handhelds
  18. Subject: HP48 digital logic simulator
  19. Keywords: HP48, digital electronics, EE
  20. Message-ID: <1094@tharr.UUCP>
  21. Date: 15 Oct 90 10:54:27 GMT
  22. Sender: pm111@tharr.UUCP
  23. Reply-To: Tony Duell <ard@siva.bristol.ac.uk>
  24. Organization: Public Access to Usenet in the UK
  25. Lines: 439
  26.  
  27.  
  28. Here's a digital circuit simulator for the HP48SX. It has 8 internal
  29. primatives: AND, OR, XOR, NOT, BUF (buffer), HI (node tied to logic 1),
  30. LO (node tied to logic 0) and CLK (clock generator of definable high and
  31. low times). It also supports nested macros defined from these elements.
  32.  
  33. A circuit is entered as a list of lists. Each sublist defines one gate (or
  34. macro-circuit) in the design. The format of the sublist is as follows : 
  35. {"NAME" I1 I2 I3..}
  36. Where NAME is either one of the primatives above or the variable name where the
  37. macro is stored entered as a string. I1 I2 etc are the names of the nodes in
  38. your circuit, and must be valid HP48 name objects (or in the case of "CLK", the
  39. first 2 arguments are integers). For example:
  40. {"AND" A1 A2 Both}  is the representation of the circuit :
  41.  
  42.   A1----------!\
  43.               ! )--------- Both
  44.   A2----------!/
  45.  
  46.   In the primatives, the inputs are always given first, and I suggest you do
  47. the same in macros (see below). 
  48.  
  49. 2 - input gates
  50. ---------------
  51. There are 3 types of 2-input gate defined, AND, OR and XOR. The formats are
  52.  
  53.  list format          equivalent expression (which you don't enter)
  54. {"AND" A1 A2 Q}       Q= A1 AND A2
  55. {"OR" A1 A2 Q}        Q= A1 OR A2
  56. {"XOR" A1 A2 Q}       Q= A1 XOR A2
  57.  
  58. 1 - input gates
  59. ---------------
  60.  
  61. There are 2 types of 1-input gate, NOT and Buffer:
  62.  
  63.  list format        equivalent expression
  64. {"NOT" A B}         B=NOT A
  65. {"BUF" A B}         B=A
  66.  
  67. Tied nodes
  68. ----------
  69. A node can also be defined as permanently high or low : 
  70.  
  71.  list format    equivalent expression
  72. {"HI" A}        A=1
  73. {"LO" A}        A=0
  74.  
  75. Clock Generators.
  76. The high and low times of the clock generator are defined in terms of
  77. time-steps which are defined as 1 horizontal pixel on the final timing diagram.
  78. Note that all gates have a propagation delay of one time-step. The format for
  79. defining a clock generator is :
  80. {"CLK" hi_time lo_time Output}
  81. Where hi_time and lo_time are real numbers giving the number of time-steps that
  82. the output will be high or low respectively and Output is the node name for the
  83. output.
  84. e.g. :
  85. {"CLK" 4 4 A} defines that node A will be low for 4 time-steps, high for 4
  86. time-steps, low for 4 time-steps etc.
  87.  
  88. A circuit is defined by creating a list of these sub-lists e.g.:
  89. {{"CLK" 2 2 A} {"CLK" 4 4 B} {"AND" A B C}}
  90.  
  91. The only commands you need to know to run the simulator are as follows:
  92.  
  93. COMPILE
  94. -------
  95. Takes the variable name where a circuit is stored in top of stack, and sets up
  96. the internal variables to represent that circuit. Use this before attempting to
  97. simulate
  98.  
  99. NODES
  100. -----
  101. Takes a list of nodes which are to appear in the final timing diagram in top of
  102. stack, and stores it in the internal variable OUT.L
  103.  
  104. ALL
  105. ---
  106. sets up OUT.L to contain _ALL_ nodes in the circuit (including the internal
  107. ones in macros). Only useful for simple circuits.
  108.  
  109. SIM
  110. ---
  111. Takes a length of simualtion in top of stack (a real number, max 100) and plots
  112. the timing diagram (in PICT) for the given circuit. After it has finished,
  113. press any key (except ATTN) to exit and restore the stack display 
  114.  
  115. Example : 
  116. Given the circuit defined above in top of stack, store it in 'CSH'
  117. then execute the following
  118. 'CSH' COMPILE            set up this circuit
  119. ALL                      we'll show all nodes
  120. 100 SIM                  draw a timing diagram.
  121.  
  122.  
  123. MACROS
  124. ------
  125. A macro-circuit is a bit like a subroutine - it's a part of a circuit (e.g. a
  126. half-adder or a flip-flop) which is used several times. For an example, see the
  127. variable HADD in the directory which contains the macro that defines a half
  128. adder.
  129. Each macro definition has the form
  130. {{External list} {{GATE1}{GATE2}...}}
  131. where {{GATE1}{GATE2}...} is the circuit description of the macro as defined
  132. above, and {External list} is the list of external connections.
  133. e.g. the 2-input multiplexor (variable MUX) in the directory
  134.  
  135. Circuit 
  136.            !\
  137. SEL --+----! >o------------!\
  138.       !    !/              ! )--!
  139.       !             A------!/   ------\----\
  140.       !                                )    )-------- Y
  141.       !             B------!\   ------/----/
  142.       !                    ! )--!
  143.       !--------------------!/
  144.  
  145.  
  146. Now, the external connections are SEL, A, B and Y
  147.  
  148.            !\     NS
  149. SEL --+----! >o------------!\
  150.       !    !/              ! )--! YA
  151.       !             A------!/   ------\----\
  152.       !                                )    )-------- Y
  153.       !             B------!\   ------/----/
  154.       !                    ! )--! YB
  155.       !--------------------!/
  156.  
  157.  
  158. I've now labeled the internal nodes (NS, YA, YB)
  159.  
  160. Thus, we get the definition:
  161. {{SEL A B Y}{{"NOT" SEL NS} {"AND" A NS YA} {"AND" B SEL YB} {"OR" YA YB Y}}}
  162.  
  163. If this is stored in the variable MUX , the element
  164. {"MUX" X Y Z GO} will be valid, with the correspondence:
  165. X -> SEL
  166. Y -> A
  167. Z -> B
  168. GO -> Y
  169.  
  170. circuits (and other macros) can be defined in terms of MUX.
  171.  
  172.  
  173. Example : the full adder
  174. ------------------------
  175. I have included a simple example to demonstrate the features of this logic
  176. simulator : the single-bit full adder.
  177. In the variable HADD is the macro for a half - adder, whereas in FADD, I have
  178. given the macro for a full-adder, defined in terms of FADD
  179. In the variable DEMO, I have defined a simple circuit with one full-adder, with
  180. its 3 input driven from clock-generators in the ratio 1:2:4. Here's how to run
  181. the demonstration:
  182. 'DEMO' COMPILE      define the circuit
  183. {M N P S C} NODES   only display the inputs and outputs
  184. 100 SIM             display the timing diagram (after it's finished, press any
  185.                     key to exit)
  186.  
  187.  
  188. I am quite willing to answer questions about how this program works, but as
  189. it's likely to be quite long, I'll only post it to the net if there is
  190. sufficient interest.....
  191. :-)
  192.  
  193. -Tony Duell
  194. ARD @ UK.AC.BRIS.PVA  (JANET)
  195. ARD @ SIVA.BRIS.AC.UK (BITNET)
  196.  
  197. (This program and its documentation are public domain. They may be freely
  198. copied, used and published in user-group newsletters provided that my name
  199. remains attached to them. They may not be sold for profit)
  200.  
  201. --------->8---------------->8----------------->8------------->8----------
  202. %%HP: T(3)A(R)F(.);
  203. DIR
  204.   DEMO { { "CLK" 5
  205. 5 M } { "CLK" 10 10
  206. N } { "CLK" 20 20 P
  207. } { "FADD" M N P S
  208. C } }
  209.   FADD { { A B CIN
  210. SUM COUT } { {
  211. "HADD" A B S1 C1 }
  212. { "HADD" CIN S1 SUM
  213. C2 } { "OR" C1 C2
  214. COUT } } }
  215.   HADD { { A B SUM
  216. CARRY } { { "XOR" A
  217. B SUM } { "AND" A B
  218. CARRY } } }
  219.   SIM
  220.     \<< INIT TITLE 1
  221. SWAP
  222.       FOR j
  223. NXTSTATE 1 OUT.L
  224. SIZE
  225.         FOR i OUT.L
  226. i GET NAME.L SWAP
  227. POS STATE SWAP GET
  228. -4 * 6 + i 1 - 8 *
  229. + R\->B j 29 + R\->B
  230. SWAP 2 \->LIST PIXON
  231.         NEXT
  232.       NEXT 7 FREEZE
  233. 0 WAIT DROP TEXT
  234.     \>>
  235.   ALL
  236.     \<< NAME.L NODES
  237.     \>>
  238.   NODES
  239.     \<< 'OUT.L' STO
  240.     \>>
  241.   COMPILE
  242.     \<< NEWC RCL DUP
  243. SIZE \-> cir siz
  244.       \<< 1 siz
  245.         FOR i cir i
  246. GET COMGATE
  247.         NEXT
  248.       \>>
  249.     \>>
  250.   MUX4 { { A B C D
  251. SA SB Y } { { "MUX"
  252. SA A B YA } { "MUX"
  253. SA C D YB } { "MUX"
  254. SB YA YB Y } } }
  255.   MUX { { SEL A B Y
  256. } { { "NOT" SEL NS
  257. } { "AND" A NS YA }
  258. { "AND" B SEL YB }
  259. { "OR" YA YB Y } }
  260. }
  261.   MACCNT 3
  262.   TITLE
  263.     \<< ERASE { # 1Eh
  264. # 0h } { # 1Eh
  265. # 3Fh } LINE OUT.L
  266. SIZE 8 MIN 1 SWAP
  267.       FOR i OUT.L i
  268. GET \->STR DUP SIZE 1
  269. - 2 SWAP SUB DUP
  270. SIZE 5 MIN 1 SWAP
  271. SUB 2 \->GROB i 1 - 8
  272. * R\->B # 0h SWAP 2
  273. \->LIST SWAP PICT 3
  274. ROLLD GOR
  275.       NEXT { # 0h
  276. # 0h } PVIEW
  277.     \>>
  278.   PPAR {
  279. (-6.5,-3.1)
  280. (6.5,3.2) X 0 (0,0)
  281. FUNCTION Y }
  282.   OUT.L { M N P S C
  283. }
  284.   NXTSTATE
  285.     \<< 1 CIRCUIT.L
  286. SIZE
  287.       FOR i
  288. CIRCUIT.L i GET DUP
  289. 1 GET "D" SWAP +
  290. OBJ\->
  291.       NEXT
  292. 'STATE.CNT' INCR
  293. DROP STATE.NEW
  294. 'STATE' STO
  295.     \>>
  296.   TMP { { "CLK" 5 5
  297. R } { "CLK" 10 10 Q
  298. } { "CLK" 20 20 P }
  299. { "MUX" P Q R S } }
  300.   STATE { 1 1 0 0 1
  301. 0 0 1 }
  302.   DCLK
  303.     \<< DUP DUP 2 GET
  304. SWAP 3 GET \-> n m
  305.       \<< STATE.CNT n
  306. m + MOD n \>= SWAP 4
  307. GET SWAP STATE.NEW
  308. 3 ROLLD PUT
  309. 'STATE.NEW' STO
  310.       \>>
  311.     \>>
  312.   DLO
  313.     \<< 2 GET
  314. 'STATE.NEW' SWAP 0
  315. PUT
  316.     \>>
  317.   DHI
  318.     \<< 2 GET
  319. 'STATE.NEW' SWAP 1
  320. PUT
  321.     \>>
  322.   DXOR
  323.     \<< DUP 2 GET
  324. STATE SWAP GET OVER
  325. 3 GET STATE SWAP
  326. GET XOR SWAP 4 GET
  327. STATE.NEW 3 ROLLD
  328. SWAP PUT
  329. 'STATE.NEW' STO
  330.     \>>
  331.   DOR
  332.     \<< DUP 2 GET
  333. STATE SWAP GET OVER
  334. 3 GET STATE SWAP
  335. GET OR SWAP 4 GET
  336. STATE.NEW 3 ROLLD
  337. SWAP PUT
  338. 'STATE.NEW' STO
  339.     \>>
  340.   DAND
  341.     \<< DUP 2 GET
  342. STATE SWAP GET OVER
  343. 3 GET STATE SWAP
  344. GET AND SWAP 4 GET
  345. STATE.NEW 3 ROLLD
  346. SWAP PUT
  347. 'STATE.NEW' STO
  348.     \>>
  349.   DNOT
  350.     \<< DUP 2 GET
  351. STATE SWAP GET NOT
  352. SWAP 3 GET
  353. STATE.NEW 3 ROLLD
  354. SWAP PUT
  355. 'STATE.NEW' STO
  356.     \>>
  357.   DBUF
  358.     \<< DUP 2 GET
  359. STATE SWAP GET SWAP
  360. 3 GET STATE.NEW 3
  361. ROLLD SWAP PUT
  362. 'STATE.NEW' STO
  363.     \>>
  364.   STATE.CNT 100
  365.   STATE.NEW { 1 1 0
  366. 0 1 0 0 1 }
  367.   INIT
  368.     \<< NAME.L SIZE
  369. CLIST DUP 'STATE'
  370. STO 'STATE.NEW' STO
  371. 0 'STATE.CNT' STO
  372.     \>>
  373.   COMGATE
  374.     \<< DUP SIZE OVER
  375. 1 GET PRIM OVER POS
  376.       IF 0 ==
  377.       THEN MACRO
  378.       ELSE 1 \->LIST
  379. SWAP 2 SWAP
  380.         FOR i OVER
  381. i GET DUP TYPE
  382.           IF 6 ==
  383.           THEN
  384. ADDNAME
  385.           END 1
  386. \->LIST +
  387.         NEXT SWAP
  388. DROP 1 \->LIST
  389. CIRCUIT.L SWAP +
  390. 'CIRCUIT.L' STO
  391.       END
  392.     \>>
  393.   ADDNAME
  394.     \<< NAME.L OVER
  395. POS DUP
  396.       IF 0 ==
  397.       THEN DROP
  398. NAME.L SWAP + DUP
  399. 'NAME.L' STO SIZE
  400.       ELSE SWAP
  401. DROP
  402.       END
  403.     \>>
  404.   NEWC
  405.     \<< { } DUP
  406. 'CIRCUIT.L' STO
  407. 'NAME.L' STO 0
  408. 'MACCNT' STO
  409.     \>>
  410.   CIRCUIT.L { {
  411. "CLK" 5 5 1 } {
  412. "CLK" 10 10 2 } {
  413. "CLK" 20 20 3 } {
  414. "XOR" 1 2 4 } {
  415. "AND" 1 2 5 } {
  416. "XOR" 3 4 6 } {
  417. "AND" 3 4 7 } {
  418. "OR" 5 7 8 } }
  419.   NAME.L { M N P
  420. S1.1 C1.1 S C2.1 C
  421. }
  422.   MACRO
  423.     \<< DROP DROP
  424. OBJ\-> 1 - \->LIST
  425. 'MACCNT' INCR \->
  426. arglist locmac
  427.       \<< OBJ\-> OBJ\->
  428. DROP \-> extrn circ
  429.         \<< 1 circ
  430. SIZE
  431.           FOR i
  432. circ i GET 2 OVER
  433. SIZE
  434.             FOR j
  435. DUP j GET DUP TYPE
  436.               IF 6
  437. ==
  438.               THEN
  439. extrn OVER POS
  440. IF 0 ==
  441. THEN \->STR 1 OVER
  442. SIZE 1 - SUB "." +
  443. locmac \->STR + "'" +
  444. OBJ\-> j SWAP PUT
  445. ELSE extrn SWAP POS
  446. arglist SWAP GET j
  447. SWAP PUT
  448. END
  449.               END
  450.             NEXT
  451. COMGATE
  452.           NEXT
  453.         \>>
  454.       \>>
  455.     \>>
  456.   PRIM { "AND" "OR"
  457. "XOR" "NOT" "BUF"
  458. "HI" "LO" "CLK" }
  459.   CLIST
  460.     \<< { } SWAP 1
  461. SWAP
  462.       START { 0 } +
  463.       NEXT
  464.     \>>
  465. END
  466.  
  467.  
  468.  
  469.